﻿using System;
using System.Collections.Generic;

namespace Chimp.Core
{
    public class VarList : JointNode
    {
        public string VarList_BlackList = "!@#$%^&*(_+-={}[]<>./|\\~`\\\" ";
        public List<Var> Vars = new List<Var>();
        public bool IsStatic = false;
        public VarList(JointNode p)
            : base(p)
        {
        }

        public override void ParseNode()
        {
            if (GetTok() != "(")
            {
                Console.WriteLine("Expeted \"(\".");
                return;
            }
            while (!Eof)
            {
                string t = GetTok();
                if (VarList_BlackList.Contains(t))
                {
                    Console.WriteLine("Unexpected token in varlist stream.");
                    return;
                }
                if (t == ",")
                {
                    continue;
                }
                if (t == ")")
                {
                    if(PeekTok()=="Static")
                    {
                        foreach(var v in Vars)
                        {
                            v.IsStatic = true;
                        }
                        IsStatic = true;
                        GetTok();
                    }
                    return;
                }

                Vars.Add(new Var(GetTok(), t));
                Console.WriteLine("Adding Var:" + Vars[Vars.Count - 1].Name + " Type:" + t);
            }
        }
    }
}